package com.tourManagement.controller;

import cn.hutool.core.lang.hash.Hash;
import com.tourManagement.entity.RT;
import com.tourManagement.entity.Route;
import com.tourManagement.service.RouteService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

@RestController
@AllArgsConstructor
@RequestMapping("/route")
public class RouteController {
    public RouteService rout;
//    @GetMapping("/test")
    @RequestMapping(method = RequestMethod.GET, value = "/test")
//    @RequestMapping(method = RequestMethod.POST, value = "/test")
    public Object test() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("label", "火车");
        hashMap.put("val", 0);
        HashMap<String, Object> hashMap1 = new HashMap<>();
        hashMap.put("label", "汽车");
        hashMap.put("val", 1);
        ArrayList<HashMap> maps = new ArrayList<>();
        maps.add(hashMap);
        maps.add(hashMap1);

        return maps;
    }
    //查询符合条件的路线
    @PostMapping("/getrouteby")
    public RT getRouteBy(Route route) throws SQLException{

        //         http://lcoalhost:8090/route/getroutebyid?start=1&end=1&date=null
        return RT.success(rout.getRouteBy(route));
    }
    //查询该条件下所有的路线
    @PostMapping("/getall")
    public RT getAll() throws SQLException{
        return RT.success(rout.getAllRoute());
    }
    //插入路线信息
    @GetMapping("/insert")
    public RT insertRoute(Route routeInfo) throws SQLException{
        return RT.success(rout.insertRoute(routeInfo));
    }
    //删除路线信息
    @GetMapping("/delete")
    public RT deleteRoute(int routeId) throws SQLException{
        return RT.success(rout.deleteRoute(routeId));
    }
    //更新用户信息
    @PostMapping("/update")
    public RT updateRoute(Route routeInfo) throws SQLException{
        return RT.success(rout.updateRoute(routeInfo));
    }
}
